package com.example.user.service.impl;

import com.example.user.entity.User;
import com.example.user.mapper.UserMapper;
import com.example.user.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

	 @Autowired
	 private UserMapper userMapper;
	 
	@Override
	public Long add(User user) {
		userMapper.insert(user);
		return user.getId();
	}


	@Override
	public List<User> getAll() {
		return userMapper.getAll();
	}

	@Override
	public PageInfo<List<User>> getList(int pageNum, int pageSize) {
		//将参数传给这个方法就可以实现物理分页了，非常简单。
		PageHelper.startPage(pageNum, pageSize);
		List<User> userList = userMapper.getAll();
		PageInfo result = new PageInfo(userList);
		return result;
	}

	@Override
	public User findById(Long id) {
		return userMapper.findById(id);
	}

	@Override
	public List<User> findByIds(List<Long> ids) {
		return userMapper.findByIds(ids);
	}

	@Override
	public PageInfo<List<User>> findListByCondition(int pageNum, int pageSize, User user) {
		PageHelper.startPage(pageNum, pageSize);
		List<User> userList = userMapper.findListByCondition(user);
		PageInfo result = new PageInfo(userList);
		return result;
	}

	@Override
	public Integer updateById(User user) {
		return userMapper.updateById(user);
	}

	@Override
	public Integer deleteById(Long userId) {
		return userMapper.deleteById(userId);
	}

	@Override
	public Integer deleteByIds(List<Long> ids) {
		return userMapper.deleteByIds(ids);
	}
}
